#define _CRT_SECURE_NO_WARNINGS 1

 
  struct ListNode {
     int val;
      struct ListNode *next;
  };
 
struct ListNode* getIntersectionNode(struct ListNode* headA, struct ListNode* headB)
{
    struct ListNode* pre1, * prt1;
    struct ListNode* pre2, * prt2;
    pre1 = prt1 = headA;
    pre2 = prt2 = headA;
    int num1 = 0, num2 = 0;
    while (pre1->next)
    {
        pre1 = pre1->next;
        num1++;
    }
    while (pre2->next)
    {
        pre2 = pre2->next;
        num2++;
    }
    if (pre1 != pre2)
    {
        return NULL;
    }
    int num = abs(num1 - num2);
    if (num1 >= num2)
    {
        while (num--)
        {
            prt1 = prt1->next;
        }
        while (prt1 != prt2)
        {
            prt1 = prt1->next;
            prt2 = prt2->next;

        }
        return prt1;
    }
    else
    {
        while (num--)
        {
            prt2 = prt2->next;
        }
        while (prt1 != prt2)
        {
            prt1 = prt1->next;
            prt2 = prt2->next;

        }
        return prt1;
    }

}